<?php
namespace api\user\controller;

use api\user\model\FaqModel;
use api\common\controller\RestBaseController;

class FaqController extends RestBaseController
{
    protected $FaqModel;

    public function __construct()
    {
        parent::__construct();
        $this->FaqModel = new FaqModel();
    }


    public function index()
    {
        $param = $this->request->param();
        if(request()->header('lang') == 'en'){
            $map['where'] = [
                'type' => 1
            ];
        }else{
            $map['where'] = [
                'type' => 0
            ];
        }
        $map['where'] = [
            'status' => 1
        ];
        if (!empty($param['page'])) {
            $map['page'] = $param['page'];
        }
        if (!empty($param['id'])) {
            $map['where']['id'] = $param['id'];
        }
        $map['order'] = '-createtime';
        $data = $this->FaqModel->getDatas($map);
        foreach ($data as &$v){
            $preUrl = request()->domain();
            $v['faq_content'] = preg_replace('#src="/([^"]+?)"#','src="'.$preUrl.'/$1"',$v['faq_content']);

        }
        $this->success('请求成功', ['list' => $data]);
    }

}
